package com.may.nio;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;

/**
 * @program: com.may.netty
 * @description:
 * @author: Bobby.Ma
 * @create: 2020-08-02 16:26
 **/
public class NIOByteBufferPutGet {
    /**
     * logger
     */
    private static final Logger log = LoggerFactory.getLogger(NIOByteBufferPutGet.class);

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(64);
        buffer.putInt(100);
        buffer.putLong(999L);
        buffer.putChar('a');
        buffer.putShort((short) 1);
        buffer.flip();
        //取出顺序必须与放置顺序一致，否则可能会抛异常
        System.out.println(buffer.getInt());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getChar());
        System.out.println(buffer.getShort());
    }
}
